package dse.messages.singleversion;

import dse.*;
import dse.messages.Message;
import dse.messages.MessageHandler;
import dse.messages.MessageSender;
import dse.messages.MessageType;
import dse.messages.multiversion.VersionReader;

public class LCVersionResponseMessageHandler extends MessageSender implements
		MessageHandler {
	private Version version;
	private VersionReader reader;
	
	public LCVersionResponseMessageHandler(Experiment exp, Version v, VersionReader reader){
		super(exp);
		this.version = v;
		this.reader = reader;
	}
	
	@Override
	public boolean acceptMessage(Message message) {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public void messageInterupted(ExperimentRecorder recorder, Message message,
			double time) {
		// TODO Auto-generated method stub
		if(ExperimentRecorder.debug)
			recorder.debug(this, "msgIntrpt: " + message, time);
		reader.readVersion(recorder, message.from(), null, time);
	}

	@Override
	public void messageReceived(ExperimentRecorder recorder, Message message,
			double time) {
		// TODO Auto-generated method stub
		if(ExperimentRecorder.debug)
			recorder.debug(this, "msgRcvd: " + message, time);
		if (message.messageType() != MessageType.LCVersionResponse) {
			recorder.warn(
					"LCVersionResponseMessageHandler recieved " + 
					message.messageType() + " message."
					);
			return;
		}
		
		reader.readVersion(recorder, message.from(), version, time);
	}

}
